﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StudentLookup.Utilities
{
    class Library
    {
        public static string RemoveSpace(string str)
        {
            while (str.Contains("  "))
            {
                str = str.Replace("  ", " ");
            }
            return str;
        }

        public static string RemoveSpecialCharacter(string str)
        {
            while (str.Contains("  ") || str.Contains("\n") || str.Contains("\r") || str.Contains("\t"))
            {
                str = str.Replace("  ", " ");
                str = str.Replace("\n", " ");
                str = str.Replace("\t", " ");
                str = str.Replace("\r", " ");
            }
            return str;
        }

        public static string LimitWords(string strInput, int limit, string dot)
        {
            if (strInput == string.Empty)
                return null;
            string strOutput = "";
            string[] str = strInput.Split(' ');
            if (limit < str.Length)
            {
                for (int i = 0; i < limit; i++)
                {
                    strOutput += str[i] + ' ';
                }
                return strOutput + dot;
            }
            else
            {
                for (int i = 0; i < str.Length; i++)
                {
                    strOutput += str[i] + ' ';
                }
                return strOutput;
            }

        }
    }
}
